﻿using MediatR;
using Traceability.App.API.Application.Command.BasicTraceability;
using Traceability.App.Domain.Traceability;
using Traceability.App.ErrorCode;
using Traceability.App.Infrastructrue.Interface;

namespace Traceability.App.API.Application.Handler.BasicTraceability
{
    public class GetGoodHandler : IRequestHandler<GetGoodCommand, APIResult<List<GoodModel>>>
    {
        private readonly IBaseRepository<GoodModel> goodRepo;

        public GetGoodHandler(IBaseRepository<GoodModel> goodRepo)
        {
            this.goodRepo = goodRepo;
        }
        public Task<APIResult<List<GoodModel>>> Handle(GetGoodCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<GoodModel>> result = new APIResult<List<GoodModel>>();
            var res = goodRepo.GetAll().Where(x => !x.IsDel).ToList();
            result.Message = "显示成功";
            result.Data = res;
            result.Code = APIEnum.Ok;
            return Task.FromResult(result);
        }
    }
}
